<?php

namespace App\Helpers\Api;


use Illuminate\Http\Request;

trait DestroyTrait
{

    public function destroy(Request $request) {
        $this->validate($request, [
            'ids' => 'required'
        ]);
        $ids = $request->input('ids');
        $arr_id = explode(",", $ids);
        foreach ($arr_id as $id) {
            $temp = $info = $this->model::find($id);
            if ($info->delete()) {
                if (method_exists($this, '_after_delete')) {
                    $this->_after_delete($temp);
                }
            }
        }
        if (method_exists($this, '_after_delete_once')) {
            $this->_after_delete_once();
        }
        return $this->success([]);
    }

}
